package com.yachang.qym.usbhost.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.yachang.qym.usbhost.R;
import com.yachang.qym.usbhost.model.OutPoliceModel;
import com.yachang.qym.usbhost.utils.LoadImage;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by qinyuanmao on 16/8/26.
 */
public class NetContactAdapter extends BaseAdapter{
    private Context mContext;
    public List<OutPoliceModel> mModels;

    public NetContactAdapter(Context context, List<OutPoliceModel> models){
        mContext = context;
        mModels = models;
    }
    @Override
    public int getCount() {
        return mModels.size();
    }

    @Override
    public Object getItem(int position) {
        return mModels.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder;
        if(convertView == null){
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_contact, null);
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.tv_contact_name);
            holder.style = (TextView) convertView.findViewById(R.id.tv_contact_style);
            holder.imageView = (CircleImageView) convertView.findViewById(R.id.iv_head);
            if(!mModels.get(position).getUserImage().equals("")){
                LoadImage.showImage(mModels.get(position).getUserImage(), holder.imageView);
            }
            convertView.setTag(holder);
        }else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.name.setText(mModels.get(position).getUserName());
        holder.style.setText("个呼");
        return convertView;
    }

    public class ViewHolder{
        public CircleImageView imageView;
        public TextView name;
        public TextView style;
    }
}
